//
//  BaseViewController.swift
//  WeiBo
//
//  Created by Wishing.Star on 2017/1/11.
//  Copyright © 2017年 Wishing.Star. All rights reserved.
//

import UIKit
//主控制器，页面功能的基类
class BaseViewController: UIViewController {

    //自定义导航栏
    lazy var navBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.cz_screenWidth(), height: 64))
    //自定义导航栏元素
    lazy var navItem = UINavigationItem()
    //自定义导航栏标题
    override var title: String? {
        //重写title的didSet
        didSet {
            navItem.title = title
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        SetupUI()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}

extension BaseViewController {
    func SetupUI() {
        view.backgroundColor = UIColor.cz_random()
        
        //加载自定义导航栏
        view.addSubview(navBar)
        //在自定义导航栏上添加按钮和标题
        //items: [UINavigationItem]?
        navBar.items = [navItem]
        //解决自定义导航栏透明度过高的问题，重新设置自定义导航栏颜色
        navBar.barTintColor = UIColor.cz_color(withHex: 0xf6f6f6)
        //修改自定义导航栏title的字体颜色
        //titleTextAttributes: [String : Any]?
        navBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.darkGray]

    }
}
